home *** CD-ROM | disk | FTP | other *** search
- #define HEADER "C++ Problem 3.1 by Rick Conn using Borland C++"
-
- #include <stdio.h>
-
- class counter {
- static int object_count;
- public:
- counter();
- static int get_count(void);
- };
-
- int counter::object_count = 0; // init count
-
- counter::counter() { counter::object_count++; }
-
- int counter::get_count(void)
- {
- return counter::object_count;
- }
-
- void main(void)
- {
- printf("%s\n", HEADER);
-
- counter c1;
- printf("The count is %d\n",
- c1.get_count());
-
- counter c2;
- printf("The count is %d\n",
- counter::get_count());
-
- counter c3;
- printf("The count is %d\n",
- c3.get_count());
-
- counter c4;
- printf("The count is %d\n",
- c4.get_count());
-
- counter c5;
- printf("The count is %d\n",
- c5.get_count());
- }
-